using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using TTXNA.src.Engine.Graphics;

namespace TTXNA.src.Engine.Create.Tools
{
    public class Toolbox
    {
        private TTXNAGame game;
        private Dictionary<ToolType, Tool> tools;
        
        public Toolbox(TTXNAGame game)
        {
            tools = new Dictionary<ToolType, Tool>();
            this.game = game;
            BuildTools();
        }

        public bool IsActive(ToolType toolType)
        {
            return tools[toolType].Active;
        }

        public void BuildTools()
        {
            //BuildRoadTool roadTool = new BuildRoadTool(game);
            //tools[ToolType.Road] = roadTool;
            
            //StationSelectTool stationSelectTool = new StationSelectTool(game);
            //tools[ToolType.StationSelect] = stationSelectTool;
            //stationSelectTool.CursorTool = true;

            //VehicleSelectTool vehicleSelectTool = new VehicleSelectTool(game);
            //tools[ToolType.VehicleSelect] = vehicleSelectTool;
            //stationSelectTool.CursorTool = true;

            LandscapingTool landscapingTool = new LandscapingTool(game);
            tools[ToolType.Landscaping] = landscapingTool;
            landscapingTool.ActiveTool = LandscapingType.Raise;

            //BusStationTool busStationTool = new BusStationTool(game);
            //tools[ToolType.BusStation] = busStationTool;

            //RoadDepotTool roadDepotTool = new RoadDepotTool(game);
            //tools[ToolType.RoadDepot] = roadDepotTool;

            //BuildTunnelTool roadTunnelTool = new BuildTunnelTool(game);
            //tools[ToolType.RoadTunnel] = roadTunnelTool;
        }

        public void MouseDown(Point mouseLocation, GridPickData data)
        {
            foreach (Tool t in tools.Values)
            {
                if (t.Active) {
                    t.MouseDown(mouseLocation, data); 
                }
            }
        }

        public void MouseUp(Point mouseLocation, GridPickData data)
        {
            foreach (Tool t in tools.Values)
            {
                if (t.Active) { t.MouseUp(mouseLocation, data); }
            }
        }

        public void MouseMove(Point mouseLocation, GridPickData data)
        {
            foreach (Tool t in tools.Values)
            {
                if (t.Active) { t.MouseMove(mouseLocation, data); }
            }
        }

        public void ChangeToolStatus(ToolType toolType, bool active)
        {
            tools[toolType].Active = active;

            if (tools[toolType].CursorTool == false && active)
            {
                foreach (Tool tool in tools.Values)
                {
                    if (tool.CursorTool) tool.Active = false;
                }
            }
            else
            {
                foreach (Tool tool in tools.Values)
                {
                    if (tool.CursorTool) tool.Active = true;
                }
            }
        }

        public Tool GetTool(ToolType toolType)
        {
            return tools[toolType];
        }

    }
}
